<template>
	<view class="control">

		<view class="section-2">
			<view class=""
				style="position: fixed;z-index: 99;top: 0;left: 0;width: 100%;background-color: #fff;padding: 20rpx 30rpx 0 30rpx;">
				<view class="">
					<u-search @search="search" @custom="search" placeholder="搜索" :showAction="false" v-model="keyword">
					</u-search>
				</view>
				<view class="list-title" style="display: flex;align-items: center;justify-content: space-between;"
					@click="addStudent">
					选择报名人员(已选{{ selectLength }})
					<!-- 剩余可选人员({{ choosenum }}) -->
					<u-icon name="plus" color="#3e80fc" label="添加"></u-icon>
				</view>
			</view>
			<!-- <view style="display: flex;align-items: center; justify-content: space-between; margin-top: 30rpx;"></view> -->

			<view class="kong flex-align" v-if="studentList.length < 1">
				<image mode="aspectFit"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/39da52a35b59c656097d7b52006f8479b6de7ba6.png">
				</image>
				<view>
					<view>报名学员资料为空</view>
					<view>请登记学员信息</view>
				</view>
			</view>
			<view class="list" v-if="studentList.length > 0">
				<view class="scroll-view_H" scroll-y="true">
					<checkbox-group shape="circle">
						<label class="item flex-between" v-for="(item, index) in studentList" :key="index"
							@click="radioChecked(index, item)">
							<view class="flex-align">
								<u--image width="50" height="50" shape="circle" :src="item.head_img">
								</u--image>
								<view class="info">
									<view class="name">
										<text style="margin-right: 15rpx;">{{ item.name||'' }}</text>
										<text style="margin-right: 15rpx;color: #2f75fa;" v-if="item.sex == 1">男</text>
										<text style="margin-right: 15rpx;color: #ff0000;" v-if="item.sex == 2">女</text>
										<text style="margin-right: 15rpx;">{{item.age||''}}</text>
										<text style="margin-right: 15rpx;">{{item.birthday||''}}</text>
									</view>
									<view class="phone">{{ item.mobile||'' }}</view>
									<view class="phone">{{ item.student_level_name||'' }}</view>
								</view>
							</view>
							<view class="radioBox" style="padding-left: 34rpx">
								<checkbox color="#2f75fa" :value="item.id" :checked="item.checked"
									:disabled="item.disabled" />
							</view>
						</label>
					</checkbox-group>
					<view style="width: 100%;height: 130rpx;"></view>
				</view>
			</view>
		</view>
		<view class="footer flex-align">
			<view class="btn" @click="doPay" v-if="selectLength>0">提交</view>
			<view class="btn btn-disbled" v-else>提交</view>
		</view>
	</view>
</template>

<script>
	const venues = require("@/api/venues/venues.js");
	export default {
		data() {
			return {
				id: 0,
				data: {},
				price_selling: "0.00",
				studentList: [],
				venue_id: 0,
				checkedNum: 0,
				spec: [],
				chooseStock: 0,
				chooseStudents: [],
				students: [],
				app_height: 0,
				arrid: [],
				selectLength: 0,
				quantity: 0,
				choosenum: '',
				skucode: "",
				sku: '',
				applicantlist: [],
				applicant: '',
				train_enum_id: '',
				sku_id: '',
				datalist: {},
				venue_id: '',
				listQuery: { //分页
					pageNo: 1,
					pageSize: 10,
				},
				totalPage: '',
				occupation_relation_id: '',
				courselist: {},
				course_item_id: '',
				coach_id: '',
				trainidname1: "",
				trainidname2: "",
				venue_name: '',
				keyword: '',
				studentslist: []
			};
		},

		onLoad(options) {
			this.venue_id = options.venue_id
		},

		methods: {
			search(value) {
				this.keyword = value
				this.selectStudent()
			},
			radioChecked(index, item) {
				this.applicantlist = []
				item.checked = !item.checked
				this.selectLength = this.studentList.filter(item => item.checked).length || 0
				this.studentList.forEach((el, idx) => {
					if (el.checked) {
						this.applicantlist.push(el.id)
					}
				})
				this.applicant = this.applicantlist.toString()
			},

			async selectStudent() {
				let that = this;
				if (this.listQuery.pageNo === 1) that.studentList = [];
				let params = {
					pageSize: this.listQuery.pageSize,
					page: this.listQuery.pageNo,
					venue_id: this.venue_id,
					keyword: this.keyword
				}
				let res = await venues.studentindex(params)
				if (res.code === 1) {
					that.studentList = that.studentList.concat(res.data.list.data); //将数据拼接在一起
					that.totalPage = res.data.list.last_page
				}
			},
			// 下拉刷新
			onReachBottom() {
				if (this.totalPage <= this.listQuery.pageNo) {
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.pageNo += 1;
				this.selectStudent()
			},
			addStudent() {
				uni.navigateTo({
					url: '../../page_system/addstudent/index?venue_id=' + this.venue_id + "&status=" + 2
				})
			},

			doPay() {
				let ticketID = this.data.id;
				this.studentList.forEach((item) => {
					if (item.checked === true) {
						this.students.push(item);
					}
				});
				uni.setStorageSync('students', this.students);
				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})

			},
		},
	};
</script>

<style scoped lang="scss">
	.control {
		width: 100%;
		min-height: 100vh;
		background-color: #ffffff;
		position: relative;

		.section-1 {
			width: 100%;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			background-color: #2f75fa;
			height: 182rpx;
			padding-bottom: 50rpx;
			position: relative;

			.image {
				width: 200rpx;
				height: 200rpx;
				position: absolute;
				z-index: 3;
				left: 30rpx;
				top: 20rpx;
				border-radius: 10rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}

				.num {
					width: 100%;
					position: absolute;
					bottom: 0;
					left: 0;
					text-align: center;
					background-color: rgba(0, 0, 0, 0.6);
					padding: 10rpx 0;
					font-size: 20rpx;
					color: #ffffff;
				}
			}

			.detail {
				margin-left: 236rpx;

				.title {
					font-size: 28rpx;
					font-weight: bold;
					color: #ffffff;
					margin-bottom: 15rpx;
				}

				.tag-list {
					.tag {
						font-size: 22rpx;
						font-weight: 500;
						color: #ffffff;
						padding: 5rpx 10rpx;
						margin-right: 10rpx;
						background-color: #4483fb;
						border-radius: 2px;
					}
				}
			}
		}

		.section-2 {
			background-color: white;
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 20rpx 30rpx 0 30rpx;
			// transform: translateY(-30rpx);


			.detail {
				margin-left: 236rpx;

				.price-1 {
					color: #ff4105;
					font-size: 32rpx;
					font-weight: 700;
					margin-right: 12rpx;
				}

				.price-2 {
					color: orange;
					font-size: 20rpx;
				}

				.price-3 {
					color: orange;
					font-size: 20rpx;
				}
			}

			.list-title {
				font-size: 28rpx;
				font-weight: bold;
				color: #000000;
				margin-top: 30rpx;
			}

			.list {
				width: 100%;
				margin-top: 140rpx;

				.scroll-view_H {
					height: 90vh;
				}

				.item {
					margin-top: 30rpx;

					.info {
						margin-left: 20rpx;

						.name {
							font-size: 26rpx;
							font-weight: 500;
							color: #333333;
						}

						.phone {
							font-size: 24rpx;
							font-weight: 500;
							color: #bebebe;
							margin-top: 10rpx;
						}
					}
				}
			}
		}

		.section-3 {
			flex-direction: column;

			text {
				margin-top: 15rpx;
				font-size: 22rpx;
				font-weight: 500;
				color: #333333;
			}
		}

		.kong {
			width: 100%;
			margin-top: 240rpx;
			justify-content: center;
			font-size: 24rpx;
			font-weight: 500;
			color: #bed2fd;
			flex-direction: column;

			image {
				width: 250rpx;
				height: 240rpx;
				margin-right: 30rpx;
			}
		}

		.footer {
			position: fixed;
			width: 100%;
			background-color: white;
			bottom: 0;
			left: 0;
			padding: 20rpx 25rpx 20rpx 25rpx;
			box-sizing: border-box;

			.menu {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 40rpx;

				image {
					width: 35rpx;
					height: 35rpx;
				}

				text {
					color: rgb(51, 51, 51);
					font-size: 24rpx;
					font-weight: 700;
					margin-top: 13rpx;
				}
			}

			.btn {
				flex: 1;
				color: rgb(255, 255, 255);
				font-size: 30rpx;
				padding: 26rpx 0;
				border-radius: 60rpx;
				background-color: #3e80fc;
				text-align: center;
				font-weight: 700;
			}

			.btn-disbled {
				flex: 1;
				color: rgb(255, 255, 255);
				font-size: 30rpx;
				padding: 26rpx 0;
				border-radius: 60rpx;
				background-color: #bebebe;
				text-align: center;
				font-weight: 700;
			}
		}

		.checkbox .wx-checkbox-input {
			border-radius: 30upx;
			/* 圆角 */
			width: 30upx;
			/* 背景的宽 */
			height: 30upx;
			/* 背景的高 */
			border: 1px solid #ccc;
			background: #eee;
		}

		/* 复选框禁用样式 */

		.checkbox .wx-checkbox-input-disabled {
			border-radius: 30upx;
			/* 圆角 */
			width: 30upx;
			/* 背景的宽 */
			height: 30upx;
			/* 背景的高 */
			background: #f3f3f3;
			border: 1px solid rgba(201, 201, 201, 1);
		}

		/* 复选框选中后样式 */

		.checkbox .wx-checkbox-input.wx-checkbox-input-checked {
			background: rgba(255, 129, 92, 1);
			border: 1px solid rgba(255, 129, 92, 1);
		}

		/*checkbox选中后图标样式 */

		.checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
			width: 30upx;
			height: 30upx;
			line-height: 30upx;
			text-align: center;
			font-size: 24upx;
			color: #fff;
			background: transparent;
			transform: translate(-50%, -50%) scale(1);
			-webkit-transform: translate(-50%, -50%) scale(1);
		}

		/deep/ checkbox .wx-checkbox-input {
			border-radius: 50% !important;
			color: #ffffff !important;
		}

		/deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked {
			color: #fff;
			background: #2851F3;
		}

		/deep/.wx-checkbox-input.wx-checkbox-input-checked {
			border: none !important;
		}

	}
</style>